#coding=utf-8
from PublicTool import HttpWrite

__author__ = 'czq'

def ClassManagerClassId(fn):
    def call(self,request,*args, **kwargs):
        if request.user.is_authenticated():
            #return HttpWrite.infoFailure(request,u'aaa')
            classId=request.GET.get('classId','')
            if classId=='':
                return HttpWrite.infoFailure(request,u'错误的板块')
            from DjangoBbs.BbsTheme.models import BbsClass
            bbsClass=BbsClass.objects.get(id=classId)
            from Permission import isClassManager
            isCm = isClassManager(request,bbsClass)
            if isCm:
                return fn(self,request, *args , **kwargs )
            else:
                return HttpWrite.infoFailure(request,u'没有管理权限')
        else:
            return HttpWrite.timeRedirect(u'请先登陆','/',3000)
    return call


def ClassManager(fn):
    def call(self,request,*args, **kwargs):
        if request.user.is_authenticated():
            #return HttpWrite.infoFailure(request,u'aaa')
            classId=kwargs['classId']
            if classId=='':
                return HttpWrite.infoFailure(request,u'错误的板块')
            from DjangoBbs.BbsTheme.models import BbsClass
            bbsClass=BbsClass.objects.get(id=classId)
            from Permission import isClassManager
            isCm = isClassManager(request,bbsClass)
            if isCm:
                return fn(self,request, *args , **kwargs )
            else:
                return HttpWrite.infoFailure(request,u'没有管理权限')
        else:
            return HttpWrite.timeRedirect(u'请先登陆','/',3000)
    return call
